#include "clien.h"
#include "ui_clien.h"

clien::clien(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::clien)
{
    ui->setupUi(this);

    socket=new QTcpSocket;
}

clien::~clien()
{
    delete ui;
}


void clien::on_cancelButton_clicked()
{
    this->close();
}


void clien::on_connectButton_clicked()
{
    //获取IP，和端口号
    QString IP=ui->ipLineEdit->text();
    QString port = ui->portLineEdit->text();

    qDebug()<<IP;
    qDebug()<<port;
    //连接
    socket->connectToHost(QHostAddress(IP),port.toShort());

    //连接成功，socket发出信号
    connect(socket,&QTcpSocket::connected,[this]()
            {

                QMessageBox::information(this,"连接提示","连接服务器成功");
            });

    //连接断开
    connect(socket,&QTcpSocket::disconnected,[this]()
            {
                QMessageBox::warning(this,"连接提示","连接断开");
            });

}

